<template>
    <view class="imagediv" :style="qiandaobg">
		<block v-if="imgurl != ''">
			<image class="img1" :src="imgurl" mode="widthFix"></image>
		</block>
        <view v-if="(first_data || null) != null" class="qiandaobox">
            <view class="ccbox">
                <view class="lianxu">
                    {{$t('fengcheche.qiandao.lianxu')}}
                    <text>{{ first_data.xu }}</text>
                    {{$t('fengcheche.qiandao.duoshaotian')}}
                </view>
                <block v-for="(kname, k) in dayarr" :key="k">
                    <view class="weui-flex" v-if="k % 7 == 0">
                        <block v-for="(wname, w) in dayarr" :key="w">
                            <view class="weui-flex__item" v-if="w >= k && w < k + 7">
                                <text v-if="first_data.xu >= wname" class="on">{{ wname }}</text>
                                <text v-else>{{ wname }}</text>
                            </view>
                        </block>
                    </view>
                </block>
            </view>
            <view v-if="first_data.is_today == 1" class="timebox">{{$t('fengcheche.qiandao.todayaready')}}</view>
            <view v-else class="timebox canqiandao" @click="qiandao">{{$t('fengcheche.qiandao.qiandao')}}</view>
        </view>
        <view v-else class="qiandaobox">
            <view class="ccbox">
                <view class="lianxu">
                    {{$t('fengcheche.qiandao.lianxu')}}
                    <text>0</text>
                    {{$t('fengcheche.qiandao.duoshaotian')}}
                </view>
                <block v-for="(kname, k) in dayarr" :key="kname.kkkk">
                    <view class="weui-flex" v-if="k % 7 == 0">
                        <block v-for="(wname, w) in dayarr" :key="wname.item">
                            <view class="weui-flex__item" v-if="w >= k && w < k + 7">
                                <text>{{ wname }}</text>
                            </view>
                        </block>
                    </view>
                </block>
            </view>
            <view class="timebox canqiandao" @click="qiandao">{{$t('fengcheche.qiandao.qiandao')}}</view>
        </view>
		<view v-if="(first_data || null) != null" class="qiandao-right">
			<view class="qiandao-nav-box">
				<view class="qd-nav" @tap="url_event" data-value="/pages/fcc/qiandao/list/list">
					<image class="img1" :src="first_data.ad01" mode="widthFix"></image>
				</view>
				<view class="qd-nav" v-if="ischoujiang" @tap="url_event" data-value="/pages/fcc/dazhuanpan/dazhuanpan">
					<image class="img1" :src="first_data.ad03" mode="widthFix"></image>
				</view>
				<block v-if="isscorestore">
					<view class="qd-nav" @tap="url_event" data-value="/pages/fcc/scorestore/index/index">
						<image class="img1" :src="first_data.ad02" mode="widthFix"></image>
					</view>
				</block>
				<block v-else>
					<view class="qd-nav" v-if="ispoints" @tap="url_event" data-value="/pages/plugins/points/index/index">
						<image class="img1" :src="first_data.ad02" mode="widthFix"></image>
					</view>
				</block>
				<view class="qd-nav" v-if="is_score_flow" @tap="url_event" data-value="/pages/fcc/qiandao/score/score">
					<image class="img1" :src="first_data.ad04" mode="widthFix"></image>
				</view>
				<view class="clear"></view>
			</view>
			<view class="qiandao_content">
				<view class="lianxu">
					{{$t('fengcheche.qiandao.qiandaoguize')}}
				</view>
				<view class="guizecontent">
					<view v-if="(first_data.guize || null) != null" class="web-html-content">
						<mp-html :content="first_data.guize" />
					</view>
				</view>
			</view>
		</view>
		<view class="clear"></view>
    </view>
</template>

<script>
const app = getApp();
export default {
    data() {
        return {
            params: null,
            data_list_loding_status: 1,
            data_list_loding_msg: '',
            data_bottom_line_status: false,
            first_data: null,
            qiandaobg:'',
            imgurl: '',
            dayarr: [],
            ischoujiang: false,
			is_score_flow:false,
			ispoints:false,
			isscorestore:false,
			flag: false,
        };
    },
	
	onLoad(params) {
	},
	
    onShow() {
		app.globalData.page_event_onshow_handle();
		this.get_first_data();
    },
    // 下拉刷新
    onPullDownRefresh() {
        this.get_first_data();
    },
    methods: {
        get_first_data() {
            var that = this; // 获取数据
			// 加载loding
			uni.showLoading({
				title: this.$t('common.loading_in_text'),
			});
			this.setData({
				data_list_loding_status: 1
			});
            uni.request({
                url: app.globalData.get_request_url('detail', 'index', 'qiandao'),
                method: 'POST',
                data: {},
                dataType: 'json',
                header: {
                    'content-type': 'application/x-www-form-urlencoded'
                },
                success: (res) => {
					uni.hideLoading();
                    uni.stopPullDownRefresh();
                    console.log(res);

                    if (res.data.code == 0) {
                        var data = res.data.data;
                        var qiandaobg = '';
                        var imgurl = '';

                        if (data.qiandaobg != '') {
                            if ((data.bgcolor || null) != null && data.bgcolor != '') {
                            	qiandaobg = 'background:'+data.bgcolor+' url(' + data.qiandaobg + ') no-repeat center top;background-size:100% auto;';
                            }else{
                            	qiandaobg = 'background:url(' + data.qiandaobg + ') no-repeat center top;background-size:100% auto;';
                            }
                        }
						if (data.qiandao_ad != '') {
							imgurl = data.qiandao_ad;
						}

                        var temp_data_list = [];

                        for (var i = 0; i < data.zhouqi; i++) {
                            temp_data_list.push(parseInt(i) + 1);
                        }

                        that.setData({
                            first_data: res.data.data || null,
                            qiandaobg: qiandaobg,
                            imgurl: imgurl,
                            dayarr: temp_data_list,
                            ischoujiang: data.ischoujiang,
							is_score_flow:data.is_score_flow,
							ispoints:data.ispoints,
							isscorestore:data.isscorestore,
							data_list_loding_status:0,
                        });
                    } else {
						if (app.globalData.is_login_check(res.data, this, 'init')) {
							app.globalData.showToast(res.data.msg);
						}
						
						this.setData({
							data_list_loding_status: 0,
							data_list_loding_msg: res.data.msg
						});
                    }
                },
                fail: () => {
                    uni.hideLoading();
					uni.stopPullDownRefresh();
					this.setData({
						data_list_loding_status: 2
					});
					app.globalData.showToast(this.$t('common.internet_error_tips'));
                }
            });
        },

        // 签到
        qiandao(e) {
            var that = this;
			if(!app.globalData.is_single_page_check()) {
			    return false;
			}
			var user = app.globalData.get_user_info(this, 'get_first_data');
			if (user != false) {
				if (that.dayarr.length < 1) {
					app.globalData.showToast(this.$t('fengcheche.qiandao.chaerro'));
					return false;
				}
				
				if(!this.flag)
				{
					this.flag = true;
					// 获取数据
					uni.request({
						url: app.globalData.get_request_url('qiandao', 'index', 'qiandao'),
						method: 'POST',
						data: {},
						dataType: 'json',
						header: {
							'content-type': 'application/x-www-form-urlencoded'
						},
						success: (res) => {
							that.flag = false;
							console.log(res);
							if (res.data.code == 0) {
								app.globalData.showToast(res.data.msg);
								
								setTimeout(function() {
									that.get_first_data();
								}, 1500);
							} else {
								app.globalData.showToast(res.data.msg);
							}
						},
						fail: () => {
							that.flag = false;
							this.setData({
								data_list_loding_status: 2
							});
							app.globalData.showToast(this.$t('common.internet_error_tips'));
						}
					});
				}
			}
        },
		
		// url事件
		url_event(e) {
		    app.globalData.url_event(e);
		}
    }
};
</script>
<style>
@import './qiandao.css';
</style>
